package com.ht.sps.nh.service.impl;

import com.ht.sps.nh.entity.TreeMenu;
import com.ht.sps.nh.service.TemplateSettingService;
import com.ht.sps.service.impl.BaseServiceImpl;
import org.nutz.dao.Cnd;
import org.nutz.ioc.loader.annotation.IocBean;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * 模板设置接口实现
 *
 * @author: 刘强
 * To change this template use File | Settings | File Templates.
 */
@IocBean(fields = { "dao" }, name = "templateSettingService")
public class TemplateSettingServiceImpl extends BaseServiceImpl<TreeMenu> implements TemplateSettingService {

    @Override
    public void saveImageName(String imgName,String titleName,int nodeId,int number,String autoFit){
        TreeMenu treeMenu = null;
        if(nodeId>0){
            treeMenu = dao().fetch(TreeMenu.class,nodeId);
            if(treeMenu!=null){
                switch (number){
                    case 1 : treeMenu.setModelUrl1(imgName+"|"+autoFit);
                        treeMenu.setTitle1(titleName);
                        break;
                    case 2 : treeMenu.setModelUrl2(imgName+"|"+autoFit);
                        treeMenu.setTitle2(titleName);
                        break;
                    case 3 : treeMenu.setModelUrl3(imgName+"|"+autoFit);
                        treeMenu.setTitle3(titleName);
                        break;
                    case 4 : treeMenu.setModelUrl4(imgName+"|"+autoFit);
                        treeMenu.setTitle4(titleName);
                        break;
                    case 5 : treeMenu.setModelUrl5(imgName+"|"+autoFit);
                        treeMenu.setTitle5(titleName);
                        break;
                }
                dao().update(treeMenu);
            }
        }
    }
    @Override
    public TreeMenu findNodeInforByNodeId(int nodeId){
        return dao().fetch(TreeMenu.class,nodeId);
    }

    @Override
    public void updateModelCount(int nodeId,int modelCount){
        if(nodeId>0){
            TreeMenu treeMenu  = dao().fetch(TreeMenu.class,nodeId);
            if(treeMenu!=null){
                treeMenu.setModelCount(modelCount);
                treeMenu.setModelUrl1("");
                treeMenu.setModelUrl2("");
                treeMenu.setModelUrl3("");
                treeMenu.setModelUrl4("");
                treeMenu.setModelUrl5("");
                dao().update(treeMenu);
            }
        }
    }

    public String updateIframeType(int nodeId,String titleName,int number,String autoFit){
        TreeMenu treeMenu = null;
        String url = "";
        if(nodeId>0){
            treeMenu = dao().fetch(TreeMenu.class,nodeId);
            if(treeMenu!=null){
                switch (number){
                    case 1 : url = treeMenu.getModelUrl1();
                        treeMenu.setModelUrl1(url.replace(url.substring(url.indexOf("|")),"|"+autoFit));
                        treeMenu.setTitle1(titleName);
                        break;
                    case 2 : url = treeMenu.getModelUrl2();
                        treeMenu.setModelUrl2(url.replace(url.substring(url.indexOf("|")),"|"+autoFit));
                        treeMenu.setTitle2(titleName);
                        break;
                    case 3 : url = treeMenu.getModelUrl3();
                        treeMenu.setModelUrl3(url.replace(url.substring(url.indexOf("|")),"|"+autoFit));
                        treeMenu.setTitle3(titleName);
                        break;
                    case 4 : url = treeMenu.getModelUrl4();
                        treeMenu.setModelUrl4(url.replace(url.substring(url.indexOf("|")),"|"+autoFit));
                        treeMenu.setTitle4(titleName);
                        break;
                    case 5 : url = treeMenu.getModelUrl5();
                        treeMenu.setModelUrl5(url.replace(url.substring(url.indexOf("|")),"|"+autoFit));
                        treeMenu.setTitle5(titleName);
                        break;
                }
                dao().update(treeMenu);
            }
        }
        return url.substring(0,url.indexOf("|"));
    }
}
